# Create your views here.
# apps/home/views.py
from django.shortcuts import render
from django.utils import timezone
from django.views import View
from celery_app.tasks.task_async import push_template_message
from django.http import JsonResponse
from home.models import UserModel
from base.logger_obj import logger
from datetime import datetime,timedelta

def index(request):
    context = {
        'title': '欢迎来到我的网站',
        'message': '这是一个使用 Django 和 uWSGI 的示例项目。',
        'now': timezone.now(),
    }
    return render(request, 'home/index.html', context)

class TestCelery(View):
    def get(self,request):
        a = request.GET.get("a",1)
        b = request.GET.get("b",2)
        push_template_message.delay()
        return JsonResponse({"code":200,"msg":"请求成功"})

class UserView(View):
    def get(self,request):
        for i in range(3):
            UserModel.objects.create(
                account=f'user{i}',
                password=f"12345",
                phone="1234567890"
            )
        return JsonResponse({"code":200,"msg":"请求成功"})

class TestDayLoggerView(View):
    def get(self,request):
        for i in range(5):
            try:
                sss
            except Exception as e:
                logger.exception(f"视图函数报错了，{e}")
        return JsonResponse({"code":200,"msg":"success"})
